﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Telerik.Web.UI;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Guru.Web.Controls.Telerik
{
    public class GuruNumericTextBox : RadNumericTextBox
    {
        public GuruNumericTextBox()
            : base()
        {
            this.Skin = GuruConfigurations.DefaultSkin;
        }
        protected Unit TextElementWidth
        {
            get 
            {
                if (ViewState["TextElementWidth"] == null) return this.defaultWidth;
                else return (Unit)ViewState["TextElementWidth"];
            }
            set 
            {
                ViewState["TextElementWidth"] = value;
            }
        }
        public override Unit Width
        {
            get
            {
                return base.Width;
            }
            set
            {
                base.Width = value;
                this.TextElementWidth = value;
            }
        }
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            string key = "Guru.Web.Controls.Telerik.GuruNumericTextBox";
            if (this.TextElementWidth.Type == UnitType.Percentage) key += ".Percentage";
            StringBuilder baseHTML = new StringBuilder();
            using (StringWriter twr = new StringWriter(baseHTML))
            {
                using (HtmlTextWriter newWriter = new HtmlTextWriter(twr))
                {
                    base.Render(newWriter);
                    newWriter.Flush();
                }
            }
            writer.Write(string.Format(HTMLTemplate.GetByKey(key), this.ClientID, baseHTML, this.TextElementWidth.Value));
        }
    }

}
